package com.heima.media.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.media.mapper.WmMaterialMapper;
import com.heima.media.service.WmMaterialService;
import com.heima.model.common.dtos.PageRequestDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.media.pojos.WmMaterial;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WmMaterialServiceImpl extends ServiceImpl<WmMaterialMapper, WmMaterial>implements WmMaterialService {

    @Autowired
    private  WmMaterialMapper wmMaterialMapper;


    /**
     * 素材分页查询
     * @param dto
     * @return
     */

    @Override
    public ResponseResult search(PageRequestDto<WmMaterial> dto) {
        //1.创建IPage
        IPage<WmMaterial> iPage=new Page<WmMaterial>(dto.getPage(),dto.getSize());
        //2.创建条件
        QueryWrapper<WmMaterial> queryWrapper = new QueryWrapper<>();
        WmMaterial body = dto.getBody();
        if (body!=null&&body.getIsCollection()!=null){
            queryWrapper.eq("is_collection",body.getIsCollection());
        }
        //3.执行查询
        IPage<WmMaterial> pageInfo = wmMaterialMapper.selectPage(iPage, queryWrapper);
        return ResponseResult.okResult(pageInfo);
    }
}
